[slug].vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <script lang='ts' setup>
  2. import { useCommonStore } from '@/stores/modules/common'
  3. import { Api } from '@/api/model/url'
  4. const route = useRoute()
  5. const commonStore = useCommonStore()
  6. const list = ref<any>([])
  7. const config = useRuntimeConfig()
  8. const { apiBaseSiteUrl } = config.public
  9. const slug = route.params.slug
  10. const { data: res } = await useAsyncData(
  11. 'category-detail',
  12. () =>
  13. $fetch(`${apiBaseSiteUrl}${Api.CategoryDetail}`, { params: { slug } }),
  14. )
  15. const seoData = res.value?.result
  16. const { data: res2 } = await useAsyncData(
  17. 'category-catalogue-list',
  18. () =>
  19. $fetch(`${apiBaseSiteUrl}${Api.CategoryCatalogueList}`, { params: { slug } }),
  20. )
  21. list.value = res2.value?.result?.records || []
  22. const { openLoginAndDownloadModal } = useLoginAndDownLoadModal()
  23. async function clickLoginAndDownload(item: any) {
  24. try {
  25. commonStore.setDownloadCatalog(item)
  26. const { status } = await openLoginAndDownloadModal()
  27. if (status)
  28. location.reload()
  29. }
  30. catch (error) {
  31. console.log(error)
  32. }
  33. }
  34. const firstTitle = computed(() => {
  35. return seoData?.contentTitle ? handleTitle(seoData.contentTitle, 1) : ''
  36. })
  37. const secondTitle = computed(() => {
  38. return seoData?.contentTitle ? handleTitle(seoData.contentTitle, 2) : ''
  39. })
  40. function handleTitle(title: string | undefined, position: number) {
  41. if (!title)
  42. return ''
  43. // 先判断标题中是否带有&,获取第一个&之前的数据和之后的数据
  44. let firstPart = ''
  45. let secondPart = ''
  46. const index = title.indexOf('&')
  47. if (index !== -1) {
  48. firstPart = title.slice(0, index).trim()
  49. secondPart = title.slice(index + 1).trim()
  50. }
  51. else {
  52. // 如果没有&,返回第一个空格之前的数据和之后的数据
  53. const spaceIndex = title.indexOf(' ')
  54. if (spaceIndex !== -1) {
  55. firstPart = title.slice(0, spaceIndex).trim()
  56. secondPart = title.slice(spaceIndex + 1).trim()
  57. }
  58. }
  59. return position === 1 ? firstPart : secondPart || ''
  60. }
  61. </script>
  62. <template>
  63. <div>
  64. <div class=" bg-#0F0820 header">
  65. <div class=" w-1200-auto pos-relative text-center flex items-center justify-start h-600px bg-no-repeat bg-center">
  66. <h1 class="text-58px fw-800 text-#fff ls-2 custom-title-font">
  67. <span class="flex items-center">
  68. {{ firstTitle }}<svgo-flower class="w-44px h-44px !text-#FFFF66 ml-20px" />
  69. </span>
  70. <span class="flex items-center">
  71. <svgo-star-blue class="w-44px h-44px text-#1AC18E mr-20px" /> {{ secondTitle }}
  72. </span>
  73. </h1>
  74. <div class="pos-absolute right-0 bottom-76px w-426px h-340px header-img-bg flex justify-center items-center">
  75. <img :src="seoData.bannerImg" alt="" class="w-full h-390px object-contain mb-40px">
  76. </div>
  77. </div>
  78. </div>
  79. <div class="py-120px w-1200-auto text-center">
  80. <h2 class="text-36px fw-800 text-#333 !mb-20px custom-title-font">
  81. Our Latest Product <span class="custom-title-bg04">Catalogs</span>
  82. </h2>
  83. <div class="text-#999 text-22px mb-40px">
  84. Discover bestsellers and fresh arrivals tailored to your niche.
  85. </div>
  86. <div class="grid grid-cols-2 gap-64px text-left">
  87. <div v-for="item in list" :key="item.id">
  88. <business-categories-comp-item :item="item" @select="clickLoginAndDownload" />
  89. </div>
  90. </div>
  91. </div>
  92. <common-block-catalogs />
  93. <common-block-blog class="!pb-0" />
  94. <AppFooter />
  95. </div>
  96. </template>
  97. <style lang='less' scoped>
  98. .header{
  99. background-image: url('@/assets/images/catalogue_bg.png');
  100. background-position: center center;
  101. background-size: cover;
  102. .header-img-bg{
  103. background-image: url('@/assets/images/catalogue_bg_img.png');
  104. background-size: cover;
  105. background-position: center;
  106. }
  107. }
  108. </style>